package gui;
import java.awt.BorderLayout;

import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;

import core.Main;
import dataStructures.MyTweet;

public class TweetsTable extends JTable {
	private static final long serialVersionUID = 1L;
	AbstractTableModel tableModel;
	JTable table;
	
	
	public TweetsTable() {
		setLayout(new BorderLayout());
		table = new JTable();
		table.getTableHeader().setReorderingAllowed(false);
		tableModel = new TweetsTableModel();
		table.setModel(tableModel);
		add(new JScrollPane(table), BorderLayout.CENTER);
	}

}

class TweetsTableModel extends AbstractTableModel {
	private static final long serialVersionUID = 1L;
	private final String[] colNames = {
		"time",
    	"user",
    	"text"
		};

	public TweetsTableModel() {

	}

	public boolean isCellEditable(int row, int col) {
		return false;
    }
	
	public int getColumnCount() { return colNames.length; }
	public int getRowCount() { return Main.data.get(Main.rowSelected).tweets.size(); }
	public String getColumnName(int col) { return colNames[col]; }
	public Object getValueAt(int row, int col) {
		MyTweet tweet = Main.data.get(Main.rowSelected).tweets.get(row);
		switch (col) {
		case 0: return tweet.time;
		case 1: return tweet.name;
		case 2: return tweet.text;
		default : return null;
		}
	}
}
